﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using Core;

namespace DAL
{
  public class ChuDeDAL
    {
        public static List<ChuDe> LayTatCa()
        {
            try
            {
                return CBO.FillCollection<ChuDe>(DataProvider.Instance.ExecuteReader("ChuDe_LayTatCa"));
            }
            catch
            {

                return new List<ChuDe>();
            }
        }
        public static bool Them(ChuDe cd)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQueryWithOutput("@IDChuDe", "ChuDe_Them", cd.IDChuDe, cd.TenChuDe, cd.MoTa);
                return Convert.ToInt32(rs) > 0;
            }
            catch
            {

                return false;
            }
        }
        public static bool Sua(ChuDe cd)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("ChuDe_Sua", cd.IDChuDe, cd.TenChuDe, cd.MoTa);
                return Convert.ToInt32(rs) > 0;
            }
            catch
            {

                return false;
            }
        }
        public static bool Xoa(string Id)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("ChuDe_Xoa", Convert.ToInt32(Id));
                return Convert.ToInt32(rs) > 0;
            }
            catch
            {

                return false;
            }
        }
        public static ChuDe LayID(string Id)
        {
            try
            {
                return CBO.FillObject<ChuDe>(DataProvider.Instance.ExecuteReader("ChuDe_LayID", Convert.ToInt32(Id)));
            }
            catch
            {
                return new ChuDe();
            }
        }
      public static List<ChuDe>TimKiemChuDe(string ten)
      {
           try
            {
                return CBO.FillCollection<ChuDe>(DataProvider.Instance.ExecuteReader("ChuDe_TimKiem",ten));
            }
            catch
            {

                return new List<ChuDe>();
            }
         
      }

    }
}
